﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business
{
    public partial class TestTime : Form
    {
        public MainForm m_mainform;
        public TestTime()
        {
            InitializeComponent();
        }

        private void but_download_Click(object sender, EventArgs e)
        {
            try
            {
                sqlbaocun("Appearance", textB_app1.Text, textB_app2.Text, textB_app3.Text);
                sqlbaocun("Chassis", textB_app1.Text, textB_app2.Text, textB_app3.Text);
                sqlbaocun("ChassisParts", textB_ChassisParts1.Text, textB_ChassisParts2.Text, textB_ChassisParts2.Text);
                sqlbaocun("Braking", textB_Braking1.Text, textB_Braking2.Text, textB_Braking3.Text);
                sqlbaocun("Lighting", textB_Lighting1.Text, textB_Lighting2.Text, textB_Lighting3.Text);
                sqlbaocun("Speed", textB_Speed1.Text, textB_Speed2.Text, textB_Speed3.Text);
                sqlbaocun("FlatBraking", textB_FlatBraking1.Text, textB_FlatBraking2.Text, textB_FlatBraking3.Text);
                sqlbaocun("MeanwhileLight", MeanwhileLight1.Text, MeanwhileLight2.Text, MeanwhileLight3.Text);
                sqlbaocun("Sideslip", textB_Sideslip1.Text, textB_Sideslip2.Text, textB_Sideslip3.Text);
                sqlbaocun("Outline", textB_Outline1.Text, textB_Outline2.Text, textB_Outline3.Text);
                sqlbaocun("CurbWeight", textB_CurbWeight1.Text, textB_CurbWeight2.Text, textB_CurbWeight3.Text);
                MessageBox.Show("完成");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }

        private void TestTime_Load(object sender, EventArgs e)
        {
            Query mquery = new Query();
            string sql = "";
            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Appearance' ");
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_app1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_app2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_app3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Chassis' ");
             dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_Chassis1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_Chassis2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_Chassis3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='ChassisParts' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_ChassisParts1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_ChassisParts2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_ChassisParts3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Braking' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_Braking1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_Braking2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_Braking3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Lighting' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_Lighting1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_Lighting2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_Lighting3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Speed' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_Speed1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_Speed2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_Speed3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='FlatBraking' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_FlatBraking1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_FlatBraking2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_FlatBraking3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='MeanwhileLight' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                MeanwhileLight1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                MeanwhileLight2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                MeanwhileLight3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Sideslip' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_Sideslip1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_Sideslip2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_Sideslip3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='Outline' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_Outline1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_Outline2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_Outline3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='CurbWeight' ");
            dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                textB_CurbWeight1.Text = dt.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                textB_CurbWeight2.Text = dt.Rows[0]["TL_TimeOther"].ToString().Trim();
                textB_CurbWeight3.Text = dt.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }
        }

        private void sqlbaocun(string name, string box1, string box2, string box3)
        {
            Query mquery = new Query();
            string sql = "";
            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='{0}'", name);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update Table_TimeLimit set TL_TimeUnOperation='{0}',TL_TimeOther='{1}',TL_TimeMotor='{2}' 
                                where TL_Name='{3}'", box1, box2, box3,name);
            }
            else
            {
                sql = string.Format(@"insert into Table_TimeLimit(TL_Name,TL_TimeUnOperation,TL_TimeOther,TL_TimeMotor) values('{0}','{1}','{2}','{3}')",
                    name, box1, box2, box3);
            }
            mquery.InsertDB(sql);
        
        }


    }
}
